package com.linchong.springboot_jpa.service;

import com.linchong.springboot_jpa.bean.User;
import com.linchong.springboot_jpa.repository.UserReposity;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @BelongsProject:springboot_jpa
 * @BelongsPackage:com.linchong.springboot_jpa.service
 * @Author:linchong
 * @CreateTime:2018-08-12 23:07
 * @Description:
 */

@Service
public class UserService {


    @Resource
    private UserReposity userReposity;

    /**
     * save 、update、delete方法需要绑定事务
     *
     * 使用@Transactional进行事务的绑定
     */

    @Transactional
    public void save(User user){
        userReposity.save(user);
    }

    @Transactional
    public void delete(int id){
        userReposity.deleteById(id);
    }


    public Iterable<User> getAll(){
        return  userReposity.findAll();
    }

}
